<include file="header" />
<div class="wraper normal" js="wapjs/meeting/js/stepthree">
	<div class="head clearfix">
		<a href="javascript:void(0);" data-href="{BEESCRM::U('/Meeting/MeetingInvite/addInviteMeeting',array('step' => 'two','lastPage' => 'three','account_id' => $accountId))}" class="iconfont icon-zuo prev-step"></a>
		<span class="head-name">会议内容</span>
		<input type="hidden" id="js_account_id" value="{BEESCRM:$accountId}">
	</div>

	<include file="new/statusbox" />

	<p class="blobk-title text-12">会议日程<a class="text-green pull-right" id="add">添加</a></p>

	<div class="lists agenda-container text-12">
		<div class="agenda-box">
			<if condition="$schedule">
				<volist name="schedule" id="vo" key="k">
					<div class="agenda-list">
						<span class="circle">{BEESCRM:$k}</span>
						<div class="form-box">
							<p class="form-list clearfix">
								<span class="field">开始时间:</span>
								<input name="start_time" class="time" placeholder="请选择时间" <if condition="$vo.start_time neq 0">value="{BEESCRM:$vo.start_time|date='Y-m-d H:i',###}"</if> />
								<if condition="$k neq 1"><a class="iconfont icon-shanchu2 pull-right" name="del"></a></if>
							</p>
							<p class="form-list clearfix">
								<span class="field">结束时间:</span>
								<input name="end_time" class="time" placeholder="请选择时间" <if condition="$vo.end_time neq 0">value="{BEESCRM:$vo.end_time|date='Y-m-d H:i',###}"</if> />
							</p>
							<p class="form-list clearfix">
								<span class="field">议程内容:</span>
								<textarea placeholder="请输入议程内容" name="content">{BEESCRM:$vo.content}</textarea>
							</p>
						</div>
					</div>
				</volist>
			<else/>
				<div class="agenda-list">
					<span class="circle">1</span>
					<div class="form-box">
						<p class="form-list clearfix">
							<span class="field">开始时间:</span>
							<input name="start_time" class="time" placeholder="请选择时间"/>
						</p>
						<p class="form-list clearfix">
							<span class="field">结束时间:</span>
							<input name="end_time" class="time" placeholder="请选择时间"/>
						</p>
						<p class="form-list clearfix">
							<span class="field">议程内容:</span>
							<textarea placeholder="请输入议程内容" name="content"></textarea>
						</p>
					</div>
				</div>
			</if>
		</div>
	</div>
	<div class="btn-box clearfix">
		<a href="{BEESCRM::U('/Meeting/MeetingInvite/addInviteMeeting',array('step' => 'two','account_id' => $accountId))}" style="background: #2db07e;" class="btn half-btn">返回</a>
		<a href="javascript:void(0)" style="background: #2db07e;" data-draft="0" url="/Meeting/MeetingInvite/addInviteMeeting/step/four/account_id/{BEESCRM:$accountId}" class="btn half-btn release">发布</a>
	</div>
</div>
<input type="hidden" id="startTime" name="startTime" value="{BEESCRM:$startTime}" />
<input type="hidden" id="endTime" name="endTime" value="{BEESCRM:$endTime}" />
<include file="../loadding" />
<script type="text/javascript" src="/assets/public/seajs/sea.js"></script>
<script enter="publicjs/public" id="confnode" async="async" src="/assets/public/config.js"></script>
<script type="text/javascript" src="/assets/public/jquery-2.1.0.min.js"></script>
<script>
	$('.prev-step').click(function(){ //上一步
		var data = {};
		var jump = $(this).attr('data-href');
		var accountId = $('#js_account_id').val();
		$.ajax({
			url:"/Meeting/MeetingInvite/saveSchdule/account_id/" + accountId,
			data:data,
			type:'post',
			success:function(result){
				location.href = jump;
			}
		});
	});


	$(document).on('click','.release, .bg-white',function() { //提交
		var startTime = $("#startTime").val();
		var endTime = $("#endTime").val();
		var data = {};
		var schedule = [];
		var temp = [];

		data.draft = $(this).data('draft');

		var flag = 0;
		var msg = '';
		var tmp_start_time = '';
		var tmp_end_time = '';
		var temp_time = '';
		var i = 0;
		if(startTime || endTime) {
			$(".form-box").each(function() {
				if(i == 0) {
				} else {
					if(temp_time > Date.parse(new Date($(this).find('input[name="start_time"]').val())) / 1000) {
						flag = 1;
						msg = '日程开始时间必须大于上一个日程的结束时间';
						return false;
					}
				}
				i = i + 1;
				tmp_start_time = Date.parse(new Date($(this).find('input[name="start_time"]').val())) / 1000;
				tmp_end_time = Date.parse(new Date($(this).find('input[name="end_time"]').val())) / 1000;

				if(tmp_start_time < startTime){
					flag = 1;
					msg = '日程开始时间不能小于会议开始时间！';
					return false;
				}
				if(tmp_end_time > endTime){
					flag = 1;
					msg = '日程结束时间不能大于会议结束时间！';
					return false;
				}

				if(tmp_start_time >= tmp_end_time){
					flag = 1;
					msg = '日程结束时间必须大于开始时间！';
					return false;
				}
				temp_time =  Date.parse(new Date($(this).find('input[name="end_time"]').val())) / 1000;

				temp.push($(this).find('input[name="start_time"]').val());
				temp.push($(this).find('input[name="end_time"]').val());
				temp.push($(this).find('textarea[name="content"]').val());
				schedule.push(temp);
				if(temp.length != 3) {
					fm.alert('请完善会议日程信息！');
				}
				temp = [];
			})
		}

		if(flag == 1){
			return false;
		}
		data.schedule = schedule;
		data.is_draft = $(this).data('draft');
		var is_draft = $(this).data('draft');
		$.ajax({
			url : "/Meeting/MeetingInvite/saveStep/step/four/account_id/{BEESCRM:$accountId}",
			data : data,
			type : 'post',

			beforeSend: function () {
				$('.circle-loadding').show();
			},
			success:function(result){
				$('.circle-loadding').hide();
				result = $.parseJSON(result);
				if(result.status == 'S'){
					location.href = "/Meeting/MeetingPersonal/index/type/3/account_id/{BEESCRM:$accountId}";
				}else if(result.status == 'F'){
					fm.alert(result.message);
				}
			}
		});
	})
</script>
<include file="footer" />